<template>
  <div class="login-box" :style="{background: `url(${assets.bg_img})`}">
    <div class="user-form" >
      <h1 class="title">
        {{title}}
      </h1>
      <div class="form-group">
        <el-icon class="iconfont"><UserFilled /></el-icon>
        <input
            autocomplete="off"
            v-model="userInfo.user_name"
            id="txtLoginId"
            name="loginId"
            type="text"
            max="20"
            placeholder="请输入账号"
            class="txt"
        />
        <p class="err"></p>
      </div>
      <div class="form-group">
        <el-icon class="iconfont"><UserFilled /></el-icon>
        <input
            autocomplete="off"
            v-model="userInfo.password"
            id="txtLoginPwd"
            type="password"
            max="20"
            placeholder="请输入密码"
            class="txt"
        />
        <p class="err"></p>
      </div>
      <div class="form-group">
        <button class="submit"  @click="handleLogin">登录</button>
      </div>
      <div class="form-group">
        <p class="msg">
          没有账号？
          <router-link to="register">点击这里注册</router-link>
        </p>
      </div>
    </div>

  </div>
</template>

<script setup>
//导入
import { useRouter, useRoute } from "vue-router";
import {reactive, ref} from "vue";
import {userStore} from "@/stores/user";
import {ElMessage} from "element-plus";
import {getAssetsImages} from "@/utils/utils";
const router = useRouter();
const title = ref(import.meta.env.VITE_TITLE)
const userInfo = reactive({
  user_name:"admin",
  password:"admin"
})
const assets = reactive({
  bg_img:getAssetsImages('bg2.png')
})
console.log(assets.bg_img,"bg_img")
const user_store = userStore()
const handleLogin = async () => {
  user_store.login(userInfo).then(res => {
    router.replace("/");
    ElMessage.success("登陆成功！")
  })
};
</script>

<style scoped>
.login-box{
    width: 100%;
    height: 100%;
    background-size: cover;
}

.user-form {
  border-radius: 15px;
  padding: 30px 80px;
  font-size: 14px;
  color: #fff;
  letter-spacing: 3px;
  width: 500px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.2);
}
.user-form a {
  text-decoration: underline;
}

.title {
  font-size: 39px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 50px auto;
}
.title img {
  height: 50px;
  margin-right: 20px;
}

.form-group {
  height: 45px;
  padding-bottom: 30px;
  position: relative;
  width: 100%;
}
.form-group .txt {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  border: 1px solid #fff;
  background: transparent;
  color: #fff;
  font-size: 16px;
  letter-spacing: 3px;
  outline: none;
  border-radius: 25px;
  padding-right: 20px;
  padding-left: 55px;
}
.form-group .txt::placeholder {
  color: #ccc;
}
.form-group .iconfont {
  position: absolute;
  left: 20px;
  font-size: 24px;
  color: #ccc;
  top: 13px;
}
.form-group .err {
  position: absolute;
  left: 20px;
  bottom: 8px;
  color: #ff8e03;
}
.form-group .submit {
  width: 100%;
  height: 100%;
  font-size: 20px;
  letter-spacing: 10px;
  border-radius: 25px;
  outline: none;
  border: none;
  cursor: pointer;
  color: rgba(0, 0, 0, 0.7);
  background: #ffda43;
  transition: 0.2s;
}
.form-group .submit:hover {
  background: #ffe57b;
}
.form-group .submit:active {
  background: #d4b534;
}
.form-group .msg {
  text-align: center;
}
</style>
